﻿<%@ WebHandler Language="C#" Class="detail" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;

public class detail : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        string authtoken = context.Request.Headers["X-ACCESS-USER"];//Header中的token
        if (string.IsNullOrEmpty(authtoken))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }
        var code = 1;
        var msg = "用户信息";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {

            double mcount = 0;

            var ucount=bll.User.Count(p => p.UIndirectParentId == authtoken);
            var _myresult = bll.S_Order.Where(p => p.ParentOopenID == authtoken&&p.OParentId==0);
            foreach (var x in _myresult)
            {
                mcount += (double)x.OLastPrice * 0.1;
            };
            var  resultpp = bll.S_Order.Where(p => p.ParentParentOopenID == authtoken&&p.OParentId==0);
            foreach (var x in resultpp)
            {
                mcount += (double)x.OLastPrice * 0.03;
            };
            var  resultppp = bll.S_Order.Where(p => p.ParentParentParentOopenID == authtoken&&p.OParentId==0);
            foreach (var x in resultppp)
            {
                mcount += (double)x.OLastPrice * 0.02;
            };


            decimal mymycount = Convert.ToDecimal(mcount);
            context.Response.Write(JsonConvert.SerializeObject(new {code,msg,time,data=new{ucount,mymycount}}));

    }

           HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }





public bool IsReusable {
    get {
        return false;
    }
}

}